package Collection;

import java.util.Deque;
import java.util.LinkedList;

/**
 * 双端队列 java.util.Deque
 * Deque继承自Queue.
 * 双端队列是队列两端都可以做出入对操作的队列。
 * 常用实现类:LinkedList
 */
public class DequeDemo {
    public static void main(String[] args) {
        Deque<String> deque = new LinkedList<>();
        deque.offer("one");
        deque.offer("two");
        deque.offer("three");
        System.out.println(deque);
        deque.offerFirst("fore");
        //从队首方向入队
        System.out.println(deque);
        //从队尾方向入队
        deque.offerLast("five");
        System.out.println(deque);

        String str =deque.poll();
        System.out.println(str);
        System.out.println(deque);
        //队首方向出队
        str =deque.pollFirst();
        System.out.println(str);
        System.out.println(deque);
        //队尾方向出队
        str =deque.pollLast();
        System.out.println(str);
        System.out.println(deque);
          //队首方向出队访问
        str = deque.peekFirst();
        System.out.println(str);
        System.out.println(deque);
        //队尾方向出队访问
        str =deque.peekLast();
        System.out.println(str);
        System.out.println(deque);

    }
}
